package com.pirestupppai.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 第一次进入引导欢迎页
 *
 * @author: xiaoluo
 * @date: 2017-03-01 14:38
 */
public class WelcomeScrollActivity extends BaseActivity{
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    private List<ImageView> mImageList = new ArrayList<>();

    @Override
    protected Context getActivityContext() {
        return this;
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initViews() {
        ImageView view0 = new ImageView(mContext);
        ImageView view1 = new ImageView(mContext);
        ImageView view2 = new ImageView(mContext);

        // 图片应放在对应大小的文件夹里,如果直接放在drawable文件夹中时,会直接生成超大图,导致一些手机viewpager滑动很卡
        view0.setBackgroundResource(R.drawable.scroll_first);
        view0.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view1.setBackgroundResource(R.drawable.scroll_second);
        view1.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view2.setBackgroundResource(R.drawable.scroll_third);
        view2.setScaleType(ImageView.ScaleType.CENTER_CROP);

        mImageList.add(view0);
        mImageList.add(view1);
        mImageList.add(view2);

        view2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mContext, InputPhoneActivity.class));
                finish();
            }
        });

        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return mImageList.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(mImageList.get(position));
                return mImageList.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(mImageList.get(position));
            }
        });
    }

    @Override
    protected void initListeners() {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initLogic() {

    }

    @Override
    public void onClick(View v) {

    }
}
